/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.sanger.das.dasregistry.springrest.types;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.biodas.jdas.dassources.utils.DasSpec;
import org.biodas.jdas.dassources.utils.DasTimeFormat;
import org.biodas.jdas.dassources.utils.PropertyFactory;
import org.biodas.jdas.schema.features.TYPE;
import org.biodas.jdas.schema.sources.*;
import org.biodas.jdas.schema.types.DASTYPES;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import uk.ac.sanger.das.dasregistry.springrest.sources.utils.RegistryTimer;

/**
 *
 * @author jw12
 */
public class DasTypesDaoImpl extends SimpleJdbcDaoSupport{
    
    private static Logger logger = Logger.getLogger(DasTypesDaoImpl.class);
    
    
    public List<TYPE> getTypesFromDb( int auto_id) {
			String sql = "select * from types where auto_id=" + auto_id;
			List<TYPE> types = getJdbcTemplate().query(sql,
                new TypesMapper());


		return types;
	}
    
    private class TypesMapper implements RowMapper<TYPE> {

        private String regPrefix = "DS_";

        public TYPE mapRow(ResultSet row, int rowNum) throws SQLException {

            TYPE type = new TYPE();
            int auto_id = row.getInt("r.auto_id");
           
            String id = row.getString("id");
				String cvId = row.getString("cvId");
				String category = row.getString("category");
				int number = row.getInt("number");

				type.setId(id);
				type.setCategory( category);
				type.setCvId(cvId);
				type.setContent(Integer.toString(number));			
            System.out.println("types="+type.toString());
            return type;
        }
    }
}
